package com.hntech.rpc.server;

import com.hntech.rpc.proxy.ProcessHandler;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Autho changqi.wu
 * @Date 路在脚下，使劲踩！
 */
public class RpcServerProxy {

    private final ExecutorService executorService = Executors.newCachedThreadPool();

    public void push(Object service,int port) {
        ServerSocket serverSocket = null;

        try {

            serverSocket = new ServerSocket(port);
            while (true) {
                final Socket socket = serverSocket.accept();
                executorService.execute(new ProcessHandler(service, socket));
            }

        } catch (Exception e) {

        } finally {
            if (serverSocket != null) {
                try {
                    serverSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


}
